//
//  SpeechManager.m
//  suRead
//
//  Created by lidi on 2018/5/30.
//  Copyright © 2018年 bao. All rights reserved.
//

#import "SpeechManager.h"
#import "BDSSpeechSynthesizer.h"
#import <AVFoundation/AVFoundation.h>

//#error 请在官网新建app，配置bundleId，并在此填写相关参数
NSString * const APP_ID = @"11304278";
NSString * const API_KEY = @"5qGfEQWKKSMGdheResUd0OCs";
NSString * const SECRET_KEY = @"ysHIqb0PCBP8bzG07a5bHLEEEfNRgDyS";

@implementation SpeechManager

-(void)configureOnlineTTS {
    [[BDSSpeechSynthesizer sharedInstance] setApiKey:API_KEY withSecretKey:SECRET_KEY];
    
    [[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryPlayback error:nil];
    //    [[BDSSpeechSynthesizer sharedInstance] setSynthParam:@(BDS_SYNTHESIZER_SPEAKER_DYY) forKey:BDS_SYNTHESIZER_PARAM_SPEAKER];
    //    [[BDSSpeechSynthesizer sharedInstance] setSynthParam:@(10) forKey:BDS_SYNTHESIZER_PARAM_ONLINE_REQUEST_TIMEOUT];
    
}

- (void)configureOfflineTTS {
    NSError *err = nil;
    // 在这里选择不同的离线音库（请在XCode中Add相应的资源文件），同一时间只能load一个离线音库。根据网络状况和配置，SDK可能会自动切换到离线合成。
    NSString* offlineEngineSpeechData = [[NSBundle mainBundle] pathForResource:@"Chinese_And_English_Speech_Female" ofType:@"dat"];
    
    NSString* offlineChineseAndEnglishTextData = [[NSBundle mainBundle] pathForResource:@"Chinese_And_English_Text" ofType:@"dat"];
    
    err = [[BDSSpeechSynthesizer sharedInstance] loadOfflineEngine:offlineChineseAndEnglishTextData speechDataPath:offlineEngineSpeechData licenseFilePath:nil withAppCode:APP_ID];
    if(err){
        //[self displayError:err withTitle:@"Offline TTS init failed"];
        return;
    }
    //[TTSConfigViewController loadedAudioModelWithName:@"Chinese female" forLanguage:@"chn"];
    //[TTSConfigViewController loadedAudioModelWithName:@"English female" forLanguage:@"eng"];
}

@end
